package recursion;

import java.util.Scanner;

//斐波那契数
public class FibonacciNumber {
    public static void main(String[] args) {
        while (true) {
            System.out.println("输入整数n,求第n个斐波那契数");
            int n = new Scanner(System.in).nextInt();
            long result = f(n);
            //System.out.printf("第%d个斐波那契数是: %d\n", n, result);
            System.out.println(result);
        }
    }

    private static long f(int n) {
        if (n < 1) { //特殊情况
            return 0;
        }
        if (n == 1 || n == 2) { //最简问题
            return 1;
        }
        return f(n - 1) + f(n - 2); //递归
    }
}
